package com.labbit.platform.manager.controller.miniprograms;

import com.labbit.platform.commons.domain.vo.Result;
import com.labbit.platform.commons.session.SessionData;
import com.labbit.platform.manager.domain.bo.MiniLoginBO;
import com.labbit.platform.manager.service.MobileMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @description:
 * @Author: CHEN YU
 * @Date: 2020-12-29 19:47
 **/
@RestController
@RequestMapping("mini/login")
public class MiniLoginController {

    @Autowired
    private MobileMessageService mobileMessageService;

    @RequestMapping("sendValidMessage")
    public Result sendValidMessage(String phone){
        mobileMessageService.sendMiniLoginMessage(phone);
        return Result.success();
    }

    @PostMapping
    public Result loginValid(@Valid @RequestBody MiniLoginBO miniLoginBO) {

        SessionData sessionData = mobileMessageService.loginValidAndRegister(miniLoginBO.getPhone(), miniLoginBO.getValidCode());
        return Result.success(sessionData);
    }

}
